package com.stable.vo.bus;

import com.alibaba.fastjson.JSONArray;
import com.stable.spider.tushare.TushareSpider;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

/**
 * 日线数据
 */
@Data
@Document(indexName = "pro_bar_info")
public class ProBarInfo extends EsBase {
	/**
	*
	*/
	private static final long serialVersionUID = 1L;

	// code+date
	@Id
	private String id;
	@Field(type = FieldType.Text)
	private String code;
	@Field(type = FieldType.Text)
	private String tsCode;
	// 日期date yyyymmdd
	@Field(type = FieldType.Long)
	private int tradeDate;
	// 开盘价
	@Field(type = FieldType.Float)
	private double open;
	// 最高价
	@Field(type = FieldType.Float)
	private double high;
	// 收盘价
	@Field(type = FieldType.Float)
	private double closed;
	// 最低价
	@Field(type = FieldType.Float)
	private double low;
	// 昨收
	@Field(type = FieldType.Float)
	private double preClose;
	// 今日涨跌额
	@Field(type = FieldType.Float)
	private double change;
	// 今日涨跌幅
	@Field(type = FieldType.Float)
	private double changeRate;
	// 交易量(手)
	@Field(type = FieldType.Float)
	private double volume;
	// 交易金额(千元)
	@Field(type = FieldType.Float)
	private double amount;
	// 5日线价格
	@Field(type = FieldType.Float)
	private double ma5;
	// 20日线价格
	@Field(type = FieldType.Float)
	private double ma20;
	// 30日线价格
	@Field(type = FieldType.Float)
	private double ma30;
	// 60日线价格
	@Field(type = FieldType.Float)
	private double ma60;
	// 250日线价格
	@Field(type = FieldType.Float)
	private double ma250;


	public ProBarInfo() {

	}

	public ProBarInfo(JSONArray arr) {
		int i = 0;
		String tscode = arr.getString(i++);// ts_code
		this.code = TushareSpider.removets(tscode);
		this.tsCode = tscode;
		this.tradeDate = Integer.valueOf(arr.getString(i++));
		this.open = Double.valueOf(arr.getString(i++));
		this.high = Double.valueOf(arr.getString(i++));
		this.low = Double.valueOf(arr.getString(i++));
		this.closed = Double.valueOf(arr.getString(i++));
		this.preClose = Double.valueOf(arr.getString(i++));// pre_close
		this.change = Double.valueOf(arr.getString(i++));// change
		this.changeRate = Double.valueOf(arr.getString(i++));// pct_chg
		this.volume = Double.valueOf((Double.valueOf(arr.getString(i++)) * 100)).longValue();// 成交量 （手）
		this.amount = Double.valueOf((Double.valueOf(arr.getString(i++)) * 1000)).longValue();// 成交额 （千元）
		i++;
		this.ma5 = Double.valueOf((Double.valueOf(arr.getString(i++))));// 5日线价格
		i++;
		this.ma20 = Double.valueOf((Double.valueOf(arr.getString(i++))));// 20日线价格
		i++;
		this.ma30 = Double.valueOf((Double.valueOf(arr.getString(i++))));// 30日线价格
		i++;
		this.ma60 = Double.valueOf((Double.valueOf(arr.getString(i++))));// 60日线价格
		i++;
		this.ma250 = Double.valueOf((Double.valueOf(arr.getString(i++))));// 250日线价格
		setId();
	}

	public void setId() {
		this.id = code + tradeDate;
	}
}
